﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace ParticleTest
{
    class elementoBenefico : Game1
    {
        Texture2D elementoTex1;

        Texture2D elementoTex2;

        Vector2 PosicaoMeteoro;

        Rectangle elementoRect;
<<<<<<< .mine

         public int VarRandom;

        static private ElementoScene currentScene;
        //public List<Vector2> blockPositions = new List<Vector2>();
=======
        static private ElementoScene currentScene;
        //public List<Vector2> blockPositions = new List<Vector2>();
>>>>>>> .r17
        public List<Vector2> elementosPositions = new List<Vector2>();

<<<<<<< .mine
        public bool isAlive = false;
        int elementoSpeed = 1;
        float elementoProbability = 0.1f;
=======
        public bool isAlive;

        int elementoSpeed = 2;

        float elementoProbability = 0.1f;
>>>>>>> .r17
        public float posicaoRect = 0f;
        Random random = new Random();
        double time = 0;

        

        public elementoBenefico(Texture2D texturaElemento1, Texture2D texturaElemento2)
        {
            elementoTex1 = texturaElemento1;
            elementoTex2 = texturaElemento2;
<<<<<<< .mine

            currentScene = ElementoScene.SCN_NORMAL;
           
            isAlive = false;
=======

            isAlive = false;
>>>>>>> .r17
        }

<<<<<<< .mine
        public void ElementoMeteor(Vector2 posicaoMeteoro)
        {
            PosicaoMeteoro.X = posicaoMeteoro.X;

            PosicaoMeteoro.Y = posicaoMeteoro.Y;

                      

            if (random.NextDouble() < elementoProbability)
            {

                elementosPositions.Add(new Vector2(PosicaoMeteoro.X, PosicaoMeteoro.Y));
            }

          

           

        }

        public void Update2(GameTime gameTime)
=======
        public void ElementoMeteor(Vector2 posicaoMeteoro)
>>>>>>> .r17
        {
            PosicaoMeteoro.X = posicaoMeteoro.X;

<<<<<<< .mine
            switch (currentScene)
=======
            PosicaoMeteoro.Y = posicaoMeteoro.Y;

            if (random.NextDouble() < elementoProbability)
>>>>>>> .r17
            {
<<<<<<< .mine
                case ElementoScene.SCN_VELOCIDADE:
                    Game1.BlockFallSpeed = 20;
                    break;

                case ElementoScene.SCN_NORMAL:
                    Game1.BlockFallSpeed = 5;
                    break;

                case ElementoScene.SCN_LIFE:

                    if (Game1.naveMae.vidaNave < 20)
                    Game1.naveMae.vidaNave = 20;
                    break;
=======

                elementosPositions.Add(new Vector2(PosicaoMeteoro.X, PosicaoMeteoro.Y));
>>>>>>> .r17
            }

<<<<<<< .mine

            if (currentScene != ElementoScene.SCN_NORMAL && currentScene != ElementoScene.SCN_LIFE)
            {
                time += gameTime.ElapsedGameTime.TotalSeconds;

                if(time > 5)
                {
                    currentScene = ElementoScene.SCN_NORMAL;

                    time = 0;
                }

            }

=======
           

        }

        public void Update2(GameTime gameTime)
        {
            #region Randomizar posiçoes

            

>>>>>>> .r17
            // Update each block
            for (int i = 0; i < elementosPositions.Count; i++)
            {
                // Animate this block falling
                elementosPositions[i] = new Vector2(elementosPositions[i].X + elementoSpeed, elementosPositions[i].Y);

                Rectangle Rect = new Rectangle((int)elementosPositions[i].X, (int)elementosPositions[i].Y, elementoTex1.Width,
                    elementoTex1.Height);

<<<<<<< .mine
                isAlive = true;

                if (elementosPositions[i].X > Window.ClientBounds.Width)
=======
                if (elementosPositions[i].X > Window.ClientBounds.Width)
>>>>>>> .r17
                {

                    elementosPositions.RemoveAt(i);
                    i--;
                }

<<<<<<< .mine
                for (int j = 0; j < Game1.cannonMissiles.Count; j++ )
                {
                    if (cannonMissiles[j].Rect.Intersects(Rect) && isAlive == true)
                    {
=======
                for (int j = 0; j < Game1.cannonMissiles.Count; j++)
                {
                    if (cannonMissiles[j].Rect.Intersects(Rect))
                    {
                        elementosPositions.RemoveAt(i);
                        i--;

                    }
   

                }

                
>>>>>>> .r17

<<<<<<< .mine

                        VarRandom = random.Next(1,3);



                        if (VarRandom == 1)
                        {
                              currentScene = ElementoScene.SCN_VELOCIDADE;
                        }

                        if (VarRandom == 2)
                        {
                            currentScene = ElementoScene.SCN_LIFE;
                        }

                        try
                        {
                            isAlive = false;

                            elementosPositions.RemoveAt(i);
                            i--;

                            break;
                        }

                        catch(ArgumentOutOfRangeException e)
                        {
                            break;
                        }


                    }
   

                }

=======
                

>>>>>>> .r17
                posicaoRect = Rect.X;          

                
            }


            for (int i = 0; i < elementosPositions.Count; i++)
            {
                // Animate this block falling
                elementosPositions[i] = new Vector2(elementosPositions[i].X + elementoSpeed, elementosPositions[i].Y);

                Rectangle Rect = new Rectangle((int)elementosPositions[i].X, (int)elementosPositions[i].Y, elementoTex1.Width,
                    elementoTex1.Height);

                
                for (int j = 0; j < Game1.cannonMissiles2.Count; j++)
                {
                    if (Game1.cannonMissiles2[j].Rect.Intersects(Rect) && isAlive == true)
                    {


                        VarRandom = random.Next(1, 3);



                        if (VarRandom == 1)
                        {
                            currentScene = ElementoScene.SCN_VELOCIDADE;
                        }

                        if (VarRandom == 2)
                        {
                            currentScene = ElementoScene.SCN_LIFE;
                        }

                        try
                        {
                            isAlive = false;
                            elementosPositions.RemoveAt(i);
                            i--;

                            break;
                        }

                        catch (ArgumentOutOfRangeException e)
                        {
                            break;
                        }

                        
                    }


                }





                posicaoRect = Rect.X;


            }

            #endregion

            
        }
        
        public void Draw(SpriteBatch thisSpritebatch)
        {
            foreach (Vector2 PosicaoElemento in elementosPositions)
                thisSpritebatch.Draw(elementoTex1, PosicaoElemento, null, Color.White, 0,
                    Vector2.Zero, 1.0f, SpriteEffects.None, 0.3f);
        }

        public enum ElementoScene
        {
            SCN_VELOCIDADE, SCN_TIRO,SCN_NORMAL,SCN_LIFE     
        }

        


    }
}
